/*
 * ObjLoader.java
 *
 *  Copyright (c) 2008 Corey Oliver and Anshul Kumaria
 *
 *  This file is part of Balls of Fury.
 *
 *  Balls of Fury is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Balls of Fury is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 *
 */

/*
 * EDIT:  03/13/2008 - This is an example of how an edit performed to the class 
 * would appear.
 */
package ballsoffury.game;

import com.jme.scene.Node;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.ObjToJme;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;

/**
 * <code>ObjLoader</code> loads an obj model given a specified path.
 *
 * @author Corey Oliver
 * @version $Revision:$ $Date:$
 */
public class ObjLoader {
    
    public static Node load(String filepath) {
        
        ObjToJme converter = new ObjToJme();
        try {
            URL objFile = BallsOfFuryGameState.class.getClassLoader().getResource(filepath);
            converter.setProperty("mtllib", objFile);
            ByteArrayOutputStream BO = new ByteArrayOutputStream();
            converter.convert(objFile.openStream(), BO);

            Node r = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            return r;
        } catch (IOException e) {
            return null;
        }
    }

    
}
